<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------

namespace plugins\auto_code\controller;

use cmf\controller\PluginAdminBaseController;
use plugins\auto_code\model\FormModel;
use think\facade\Db;
use tree\Tree;

/**
 * Class AdminIndexController.
 */
class AdminIndexController extends PluginAdminBaseController
{
    protected function initialize()
    {
        parent::initialize();
        $adminId = cmf_get_current_admin_id(); //获取后台管理员id，可判断是否登录
        if (!empty($adminId)) {
            $this->assign('admin_id', $adminId);
        }
    }

    /**
     * 代码生成器
     * @adminMenu(
     *     'name'   => '代码生成器',
     *     'parent' => 'admin/Plugin/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '代码生成器插件',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $tree = new Tree();
        $result = Db::name('AdminMenu')->where("status", 1)->order(["list_order" => "ASC"])->select()->toArray();

        $database = config('database.connections.mysql.database');
        $sql = "SELECT table_name,TABLE_COMMENT as t_comment,ENGINE as t_engine  FROM information_schema.tables WHERE table_schema = '{$database}' AND table_type = 'base table'";
        $tableArr = Db::query($sql);

        $this->assign('tableArr', $tableArr);

        $str = "<option value='\$id'>\$spacer \$name</option>";
        $tree->init($result);
        $selectCategory = $tree->getTree(0, $str);
        $this->assign("category", $selectCategory);
        return $this->fetch('/admin_index');
    }
}
